﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using UCS.ArtificialInteligence.AI;
using UCS.ArtificialInteligence.CitiesProblem.Model;
using UCS.ArtificialInteligence.CitiesProblem.View.Commands;

namespace UCS.ArtificialInteligence.CitiesProblem.View.ViewsModels
{
    public class CountryViewModel : INotifyPropertyChanged
    {
        #region Attributes and Properties

        private Country _country;
        public Country Country
        {
            get { return _country; }
            set
            {
                _country = value;

                RaisePropertyChanged("Country");
            }
        }

        private List<City> _cities;
        public IEnumerable<City> Cities
        {
            get { return _cities; }
        }

        private ProblemState _firstPath;
        public ProblemState FirstPath
        {
            get { return _firstPath; }
            set
            {
                _firstPath = value;

                RaisePropertyChanged("FirstPath");
            }
        }

        private FindFirstPathCommand _findFirstPathCommand;
        public FindFirstPathCommand FindFirstPathCommand
        {
            get { return _findFirstPathCommand; }
            set { _findFirstPathCommand = value; }
        }

        private City _from;
        public City From
        {
            get { return _from; }
            set
            {
                _from = value;

                RaisePropertyChanged("From");
            }
        }

        private City _to;
        public City To
        {
            get { return _to; }
            set
            {
                _to = value;

                RaisePropertyChanged("To");
            }
        }

        private ListType _listType;
        public ListType ListType
        {
            get { return _listType; }
            set
            {
                _listType = value;

                RaisePropertyChanged("ListType");
            }
        }

        #endregion

        #region Events

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region Constructors

        public CountryViewModel(Country country)
        {
            _country = country;
            _findFirstPathCommand = new FindFirstPathCommand(this);

            _cities = new List<City>();

            _listType = ListType.Amplitude;

            foreach (var state in _country.States)
                _cities.AddRange(state.Cities);
        }

        #endregion

        #region Private Methods

        private void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion
    }
}
